<template>
  <div class="login-page">
    <h1>登录页面</h1>
    <form @submit.prevent="onSubmit">
      <div>
        <label>用户名:</label>
        <input v-model="username" required />
      </div>
      <div>
        <label>密码:</label>
        <input v-model="password" type="password" required />
      </div>
      <button type="submit">登录</button>
    </form>
    <p>
      没有账号？<router-link to="/register">注册</router-link>
    </p>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter, useRoute } from 'vue-router';

const router = useRouter();
const route = useRoute();
const username = ref('');
const password = ref('');

const onSubmit = () => {
  // 模拟登录
  setTimeout(() => {
    alert('登录成功！');
    const redirectPath = route.query.redirect || '/';
    router.replace(redirectPath);
  }, 1000);
};
</script>

<style scoped>
.login-page {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
}
form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin: 20px 0;
}
input {
  padding: 8px;
  width: 100%;
  margin-top: 5px;
}
button {
  padding: 10px;
  background: #4caf50;
  color: white;
  border: none;
  cursor: pointer;
}
</style> 